#ifndef PROJECTZ_NUSER_NCOMMAND_CMD_CS_REQ_TILTE_GET_H_
#define PROJECTZ_NUSER_NCOMMAND_CMD_CS_REQ_TILTE_GET_H_

#include "../../engine.h"

#include "../../User.h"

#include "../../NLogic/Bag.h"
#include "../../NLogic/Item.h"
#include "../../xldata/item_common.h"

#include "../../NResource/Static.h"

namespace ProjectZ { namespace NCommand { namespace NWorld {

class CS_REQ_TITLE_GET
{
public:
	static void OnExecute(User * pUser, ::Network::Packet * pPacket)
	{
		PREPARE_PACKET;

		char tid = 0;
		*pPacket >> tid;

		NLogic::Bag * pBag = pUser->GetBag(BAG_TYPE_TITLE);
		if (NULL == pBag)
		{
			return;
		}

		NLogic::Item::Data clsData;
		clsData.tid = tid;
		clsData.sub_type = static_cast<int>(EnumClassItemTableType::CLASS_ITEM_TABLE_TITLE);
		clsData.quantity = 1;
		clsData.class_type = -1;

		NResource::ItemResource::ITEMRESOURCETREE & tree
			= NResource::Static::Instance().GetItemResource()->GetItemResourceTree(CLASS_ITEM_TABLE_TITLE);
		NResource::ItemResource::Key clsKey(tid, -1);
		auto itr = tree.find(clsKey);
		if (itr == tree.end())
		{
			DEBUGLOG("CS_REQ_TITLE_GET : Invalid tid=%d!!", tid);
			return;
		}

//		NLogic::Item * pItem = NLogic::s_clsItemPool.NEW();
//		pItem->Open_Normal(clsData, pUser);

//		if (false == pBag->AddItem(pItem))
//		{
//			NLogic::s_clsItemPool.DEL(pItem);
//			return;
//		}

		bool bBagFull = false;
		NLogic::Item * pItem = pBag->AddItemWithData(clsData, bBagFull);
		if (NULL == pItem)
		{
			// TODO
			return;
		}

		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		pAck->MakePacket(CMD_SC_REQ_TITLE_GET);
		pUser->Send(pAck);
	}
};

} /*NWorld*/ } /*NCommand*/ } /*ProjectZ*/


#endif /* PROJECTZ_NUSER_NCOMMAND_CMD_CS_REQ_TILTE_GET_H_ */
